Artificial Intelligence Based Safety Solution for Accident

Click Here to View Step by Step

 

Intro project:

AI can easily detect cars and give alerts to prevent accidents, thus compensating for human limitations. Basic ML algorithms can be used to track driving behavior and convert driving behavior into good driving scores.
AI and its Effect on Workplace Safety
IoT is a unique smart system that uses tiny sensors to monitor everything from individual machines to entire production lines, employees, and everything. Once the sensors are in place, the ML model monitors each individual element, identifies potential risks, and AI proposes solutions. Since AI has an impressive ability to predict future trends, it's able to pinpoint health risks and notify you before anything goes wrong.

You can set up predictive alerts and notifications throughout the entire system to minimize potential risks. Depending on the industry in question, such a system can save lives and prevent serious injuries. 

 

Ultrasonic Distance Sensor - HC-SR04

 

 

HC-SR04 Hardware Overview

HC-SR04


The HC-SR04 is an affordable and easy-to-use distance-measuring sensor that has a range from 2cm to 400cm (about an inch to 13 feet).

The sensor is composed of two ultrasonic transducers. One is a transmitter that outputs ultrasonic sound pulses and the other is a receiver that listens for reflected waves.

 

Operating Voltage 5V DC
Operating Current 15mA
Operating Frequency 40KHz
Min Range 2cm / 1 inch
Max Range 400cm / 13 feet
Accuracy 3mm
Measuring Angle <15°
Dimension 45 x 20 x 15mm

 

 

Required parts

 

  • Arduino uno r3

  • 2 * bHC-SR04

  • 2 * Traffic Light LED Display Module

 

 

AI-Based Safety

#define trigPin 2            //sensor A
#define echoPin 3          //sensor A
#define btrigPin 7          //sensor B
#define bechoPin 8         //sensor B
#define LED 13
#define LED2green 12 // initialize variables
long d1;                  // sensor 1 distance                
long d2;                  // sensor 2 distance
long t1 = 0;              // sensor 1 timestamp; initialize as 0
long t2 = 0;              // sensor 2 timestamp; initialize as 0
unsigned long start_time; // time since program start
float max_distance = 10;  // movement sensing range (in cm)
long sensor1=0;
long sensor2=0;
long sensorno=0;
void setup() {
  Serial.begin (115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(btrigPin, OUTPUT);
  pinMode(bechoPin, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(LED2green, OUTPUT);
    start_time = millis();  // get program start time
} void loop() {
  int  walid=0;
  int bduration, bdistance;
  digitalWrite(btrigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(btrigPin, LOW);
  bduration = pulseIn(bechoPin, HIGH);
  bdistance = (bduration/2) / 29.1;
  
  int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
     
  if (distance >= 3 && distance <= 10)
  {
     t1 = millis();
  Serial.print(distance);
   Serial.println(" cm");
   sensor1=1;
 //Serial.println(" t1");
      //     Serial.println(t1);
      //         Serial.println(" t2");
     //      Serial.println(t2);              // if both sensors have nonzero timestamps
                if (t2 < t1) 
                  {  
                    
                    // if left sensor triggered first
                    Serial.println("Left to right");    // direction is left to right
                
                  } 
               else if (t1 < t2) 
                  {    
                    // if right sensor triggered first
                     Serial.println("Right to left");    // direction is right to left
                   
            
             }
               delay(1000);
      
  }
  else if (bdistance >= 3 && bdistance <= 10)
  {       Serial.print(bdistance);
    Serial.println(" cm");
       t2 = millis();
      sensor2=1;
              //       Serial.println(" t1");
             //   Serial.println(t1);
      // Serial.println(" t2");
             //    Serial.println(t2);      
                if (t2 < t1) 
                  {                      // if left sensor triggered first
                    Serial.println("Left to right");    // direction is left to right
                   
                  } 
               else if (t1 < t2) 
                  {                 // if right sensor triggered first
                    Serial.println("Right to left");    // direction is right to left
                    
               
                  }
           delay(1000);      
    }        if (sensor2==1 )
{
     Serial.println("two"); 
    Serial.println(sensor2); 
      Serial.println(sensor1); 
      digitalWrite(LED, HIGH);
      digitalWrite(LED2green, LOW);
       if (sensor1==1)
       {
            sensor1=0;
           sensor2=0;
       }
  }
  else if (sensor1==1)
  {
      Serial.println("one"); 
    Serial.println(sensor2); 
      Serial.println(sensor1); 
      digitalWrite(LED, HIGH);
      digitalWrite(LED2green, LOW);         if (sensor2==1)
       {
           sensor1=0;
           sensor2=0;
       }
      
  }
  else if (sensor2 ==0 && sensor1==0)
  {
   
      digitalWrite(LED, LOW);
      digitalWrite(LED2green, HIGH);
  
 
    
    }
  /*if (distance > 10 && bdistance > 10) 
  {
   t1 = 0;
    t2 = 0;
               digitalWrite(LED,LOW );
          digitalWrite(LED2green,HIGH );
  }
  /*
 
  
 
  /*
   if (bdistance >= 3 && bdistance <= 200)
  {
 
   
    digitalWrite(LED2, HIGH);
  }
  
  else {
     Serial.println("Out of range");
     digitalWrite(LED, LOW);
     digitalWrite(LED2, LOW);
  }
  */
  delay(1000);
}